﻿import plugin from '../../lib/plugins/plugin.js';
import common from "../../lib/common/common.js";
import moment from "moment"

let zt = 0
let time = [9, 12, 15, 18, 21]  //需要报点的时间整点
let gid = []  //白名单群号
let bid = []  //黑名单群号

//1.定义命令规则
export class example extends plugin {
  constructor() {
    super({
      /** 功能名称 */
      name: '整点报时',
      /** 功能描述 */
      dsc: '简单开发示例',
      /** https://oicqjs.github.io/oicq/#events */
      event: 'message',
      /** 优先级，数字越小等级越高 */
      priority: 10000,
	  rule: [
                {
                    reg: "^#?cstime(.*)$",
                    fnc: "baoshi",
					permission: "master"
                },
	        ]
    })
	this.task = {
      cron: `0 0 ${time.join(',')} * * *`,
      name: '全部群聊整点报时',
      fnc: () => this.baoshi()
    }
  }
  

  async baoshi() {
	if (zt != 1) return
	let hour = moment().format("h");
	let day = moment().format("a")
    if (gid.length == 0) {
        let listMap = Array.from(Bot.gl.values())
        listMap.map(item => gid.push(item.group_id))
	    }
		for (let id of gid) {
		    if (isNaN(id)) {
                continue
            }
		    if (bid.includes(id)) {
			    logger.info(`${id} 黑名单不推送`)
			    continue 
		    }	
			await Bot.pickGroup(id).sendMsg(`${day} ${hour}点几嘞~`)
		    await common.sleep(1000)
        }
    }
  
 
}